﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace HelloWeb
{
    /// <summary>
    /// HelloWS 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    [System.Web.Script.Services.ScriptService]
    public class HelloWS : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        //[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
        public string searchPhone(string number)
        {
            if (number.Length < 7)
                return "Invalid Parameters";

            number = number.Substring(0, 7);
            HelloWeb.PhonetTableAdapters.PhonetmpTableAdapter adapter = new PhonetTableAdapters.PhonetmpTableAdapter();
            var row = adapter.GetDataByNumber(number).First();
            return $"{row.Province}{row.Area}, {row.Provider}";
        }
    }
}
